package com.zhongli.devplatform.service.impl.sys;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongli.devplatform.mapper.sys.ReadChapterMapper;
import com.zhongli.devplatform.po.sys.ReadChapterPO;
import com.zhongli.devplatform.po.view.ViewUserToSchoolPO;
import com.zhongli.devplatform.service.imp.sys.ReadChapterService;
import com.zhongli.devplatform.service.imp.view.ViewUserToSchoolPOService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wy
 * @since 2020/7/31
 */
@Service
public class ReadChapterServiceImpl extends ServiceImpl<ReadChapterMapper, ReadChapterPO> implements ReadChapterService {

    @Resource
    private ViewUserToSchoolPOService userToSchoolPOService;

    @Resource
    private ReadChapterMapper chapterMapper;

    /**
     * 根据当前学生的班级 查询当前班级的所有章节
     * @param currentStu 当前学生id
     * @return list集合
     */
    @Override
    public List<ReadChapterPO> getCurrentStuChapter(Integer currentStu) {
        ViewUserToSchoolPO view = userToSchoolPOService.getById(currentStu);
        return chapterMapper.selectList(new QueryWrapper<ReadChapterPO>()
                .eq("school_id", view.getSchoolId())
                .eq("grade_id",view.getGradeId()));
    }
}
